/*
 *  Copyright (C) 2011 geoForge Project
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package com.tempo.defaul;

/**
 *
 * @author Amadeus.Sowerby
 *
 * email: Amadeus.Sowerby_AT_gmail.com
 * ... please remove "_AT_" from the above string to get the right email address
 */

public class StopWatch {

    public StopWatch(){

    }

    
    public static void start(String strWhat)
    {
        StopWatch._START_TIME_ = System.currentTimeMillis();
        StopWatch._STR_WHAT_ = strWhat;
    }
    
    public static void start()
    {
        System.out.println("start chrono");
        StopWatch._START_TIME_ = System.currentTimeMillis();
    }
    
    public static String end()
    {
        StopWatch._END_TIME_ = System.currentTimeMillis();


        int fullMillis = (int)(_END_TIME_ - _START_TIME_);


        int hour = 0;
        int minute = 0;
        int second = 0;
        int millis = 0;

        String strReturn = "";

            millis = fullMillis % 1000;
            int fullSecond = fullMillis/1000;
            
            second = fullSecond % 60;
            int fullMinutes = fullSecond/60;

            minute = fullMinutes % 60;

            hour =  fullMinutes/60;


       String strMin= "";
       String strSec= "";
       String strHour= "";
       String strMillis= "";


       if (hour < 10)
           strHour = "0";
       if (minute < 10)
           strMin = "0";
       if (second < 10)
           strSec = "0";
       if (millis < 10)
           strMillis = "00";
       if (millis < 100)
           strMillis = "0";


        strReturn = _STR_WHAT_ + "  -> " + 
                strHour + hour + ":" +
                strMin + minute + "'" +
                strSec + second +  "''" +
                strMillis + millis;

        return strReturn;
    }
    public static String end(String strWhat)
    {
        StopWatch._END_TIME_ = System.currentTimeMillis();


        int fullMillis = (int)(_END_TIME_ - _START_TIME_);


        int hour = 0;
        int minute = 0;
        int second = 0;
        int millis = 0;

        String strReturn = "";

            millis = fullMillis % 1000;
            int fullSecond = fullMillis/1000;
            
            second = fullSecond % 60;
            int fullMinutes = fullSecond/60;

            minute = fullMinutes % 60;

            hour =  fullMinutes/60;


       String strMin= "";
       String strSec= "";
       String strHour= "";
       String strMillis= "";


       if (hour < 10)
           strHour = "0";
       if (minute < 10)
           strMin = "0";
       if (second < 10)
           strSec = "0";
       if (millis < 10)
           strMillis = "00";
       if (millis < 100)
           strMillis = "0";


        strReturn = strWhat + "  -> " + 
                strHour + hour + ":" +
                strMin + minute + "'" +
                strSec + second +  "''" +
                strMillis + millis;

        return strReturn;
    }

    private static long _START_TIME_ = 0;
    private static long _END_TIME_ = 0;
    private static String _STR_WHAT_ = "";

}
